package com.huizu.project.service.impl;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.huizu.common.enums.BasicLabourCategoryEnum;
import com.huizu.common.utils.DateUtils;
import com.huizu.common.utils.StringUtils;
import com.huizu.project.domain.ProBj;
import com.huizu.project.domain.ProUser;
import com.huizu.project.mapper.ProUserMapper;
import com.huizu.project.vo.*;
import org.apache.ibatis.javassist.runtime.Desc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.huizu.project.mapper.BurialPointMapper;
import com.huizu.project.domain.BurialPoint;
import com.huizu.project.service.IBurialPointService;

/**
 * 动作埋点Service业务层处理
 *
 * @author zhangmx
 * @date 2024-09-27
 */
@Service
public class BurialPointServiceImpl implements IBurialPointService
{
    @Autowired
    private BurialPointMapper burialPointMapper;

    @Autowired
    private ProUserMapper proUserMapper;

    /**
     * 查询动作埋点
     *
     * @param id 动作埋点主键
     * @return 动作埋点
     */
    @Override
    public BurialPoint selectBurialPointById(Long id)
    {
        return burialPointMapper.selectBurialPointById(id);
    }

    /**
     * 查询动作埋点列表
     *
     * @param burialPoint 动作埋点
     * @return 动作埋点
     */
    @Override
    public List<BurialPoint> selectBurialPointList(BurialPoint burialPoint)
    {
        return burialPointMapper.selectBurialPointList(burialPoint);
    }

    /**
     * 新增动作埋点
     *
     * @param burialPoint 动作埋点
     * @return 结果
     */
    @Override
    public int insertBurialPoint(BurialPoint burialPoint)
    {
        burialPoint.setCreateTime(DateUtils.getNowDate());
        return burialPointMapper.insertBurialPoint(burialPoint);
    }

    /**
     * 修改动作埋点
     *
     * @param burialPoint 动作埋点
     * @return 结果
     */
    @Override
    public int updateBurialPoint(BurialPoint burialPoint)
    {
        return burialPointMapper.updateBurialPoint(burialPoint);
    }

    /**
     * 批量删除动作埋点
     *
     * @param ids 需要删除的动作埋点主键
     * @return 结果
     */
    @Override
    public int deleteBurialPointByIds(Long[] ids)
    {
        return burialPointMapper.deleteBurialPointByIds(ids);
    }

    /**
     * 删除动作埋点信息
     *
     * @param id 动作埋点主键
     * @return 结果
     */
    @Override
    public int deleteBurialPointById(Long id)
    {
        return burialPointMapper.deleteBurialPointById(id);
    }

    @Override
    public LargeScreenTopVO getTopData() {
        LargeScreenTopVO vo = burialPointMapper.getTopData();
        List<LargeScreenCenterVo> centerVo = burialPointMapper.getTopDataGroupMonth();
        List<String> recentMonths = getRecentMonths(6);

        // 删除不在最近6个月的数据
        centerVo.removeIf(next -> !recentMonths.contains(next.getMonth()));
        // 获取已经存在的月份
        ArrayList<String> haveMouth = new ArrayList<>();
        centerVo.forEach(screenCenterVo -> {
            haveMouth.add(screenCenterVo.getMonth());
        });

        // 除去月份交集，得到最近6个月没有的月份
        List<String> intersection = recentMonths.stream().filter(center ->
                !haveMouth.contains(center)).collect(Collectors.toList());
        intersection.forEach(mouth -> {
            LargeScreenCenterVo screenCenterVo = new LargeScreenCenterVo();
            screenCenterVo.setMonth(mouth);
            screenCenterVo.setNumber("0");
            centerVo.add(screenCenterVo);
        });

        // 根据月份排序
        centerVo.sort(Comparator.comparing(LargeScreenCenterVo::getMonth));
        vo.setCenterVoList(centerVo);

        return vo;
    }

    @Override
    public LargeScreenLeftVO getLeftData() {
        LargeScreenLeftVO largeScreenVO = new LargeScreenLeftVO();
        // 获取劳动教育总得分（以学院、年级为纬度）
        List<LabourEducationAverageVO> list = burialPointMapper.getLabourEducationAverageByXyAndNj();
        // 按年级进行分组
        Map<String, List<LabourEducationAverageVO>> njNameGroup = list.stream().
                collect(Collectors.groupingBy(LabourEducationAverageVO::getNjName));
        // 按学院进行分组
        Map<String, List<LabourEducationAverageVO>> xyIdGroup = list.stream().
                collect(Collectors.groupingBy(LabourEducationAverageVO::getXyId));

        // 转换成array
        ArrayList<String> njNameArrays = new ArrayList<>(njNameGroup.keySet());
        ArrayList<String> xyIdGroupArrays = new ArrayList<>(xyIdGroup.keySet());

        ArrayList<LargeScreenLeftClidrenVO> largeScreenLeftVOS = new ArrayList<>();
        HashMap<String, String> emphasisMap = new HashMap<>();
        emphasisMap.put("focus","series");
        ArrayList<String> xyNames = new ArrayList<>();
        // 组装数据
        for (int njNumber = 0; njNumber < njNameGroup.size(); njNumber++) {
            LargeScreenLeftClidrenVO largeScreenLeftVO = new LargeScreenLeftClidrenVO();
            largeScreenLeftVO.setName(njNameArrays.get(njNumber));
            largeScreenLeftVO.setType("bar");
            largeScreenLeftVO.setStack(njNameArrays.get(njNumber));
            largeScreenLeftVO.setEmphasis(emphasisMap);
            ArrayList<String> dataArrays = new ArrayList<>();
            for (int xyNumber = 0; xyNumber < xyIdGroup.size(); xyNumber++) {
                BigDecimal xyNjCount = BigDecimal.ZERO;
                int peoples = 0;
                for (LabourEducationAverageVO vo : list) {
                    if (njNameArrays.get(njNumber).equals(vo.getNjName())
                    && xyIdGroupArrays.get(xyNumber).equals(vo.getXyId())) {
                        if (peoples == 0) {
                            xyNames.add(vo.getXyName());
                        }
                        BigDecimal jcldCj = vo.getUserjcldCj().setScale(2, RoundingMode.HALF_UP);
                        BigDecimal cgCj = vo.getUserldcgCj().setScale(2, RoundingMode.HALF_UP);
                        BigDecimal gyCj = vo.getUserldgyCj().setScale(2, RoundingMode.HALF_UP);
                        BigDecimal zjCj = vo.getUserldzjCj().setScale(2, RoundingMode.HALF_UP);
                        BigDecimal llCj = vo.getUserllCj().setScale(2, RoundingMode.HALF_UP);

                        BigDecimal jcldCjZS = jcldCj.multiply(BigDecimal.valueOf(0.6)).setScale(2, RoundingMode.HALF_UP);
                        BigDecimal ldzjCjZS = zjCj.multiply((BigDecimal.valueOf(0.2))).setScale(2, RoundingMode.HALF_UP);
                        BigDecimal ldgyCjZS = gyCj.multiply((BigDecimal.valueOf(0.1))).setScale(2, RoundingMode.HALF_UP);
                        BigDecimal ldcgCjZS = cgCj.multiply((BigDecimal.valueOf(0.1))).setScale(2, RoundingMode.HALF_UP);
                        BigDecimal countSjZs = jcldCjZS.add(ldzjCjZS).add(ldgyCjZS).add(ldcgCjZS);
                        BigDecimal allCount = llCj.multiply(BigDecimal.valueOf(0.2)).add(countSjZs.multiply(BigDecimal.valueOf(0.8)));
                        xyNjCount = xyNjCount.add(allCount);
                        peoples++;
                    }
                }
                dataArrays.add(xyNjCount.compareTo(BigDecimal.ZERO) > 0 && peoples > 0
                        ?  xyNjCount.divide(new BigDecimal(peoples),2,RoundingMode.HALF_UP).toString()
                        : "");
            }
            largeScreenLeftVO.setData(dataArrays.toArray(new String[0]));
            largeScreenLeftVOS.add(largeScreenLeftVO);
        }
        largeScreenVO.setXys(xyNames.toArray(new String[0]));
        largeScreenVO.setClidrenVOS(largeScreenLeftVOS);

        return largeScreenVO;
    }

    @Override
    public List<LargeScreenRightVO> getRightData() {
        // 获取基础劳动按类别得分
        List<LargeScreenRightVO> list = burialPointMapper.getRightData();
        // 获取全校总得分
        String allCount = burialPointMapper.getLabourAllCount();

        // 计算出占比
        // 基础劳动单项全校总得分/基础劳动全校总积分数
        for (LargeScreenRightVO largeScreenRightVO : list) {
            String count = "0";

            // 分子与分母都不能为0
            if (!StringUtils.isEmpty(largeScreenRightVO.getValue())
                    && Integer.parseInt(largeScreenRightVO.getValue()) > 0
                    && !StringUtils.isEmpty(allCount)
                    && Integer.parseInt(allCount) > 0) {
                count = new BigDecimal(largeScreenRightVO.getValue())
                        .divide(new BigDecimal(allCount),2,RoundingMode.HALF_UP)
                        .multiply(new BigDecimal(100))
                        .toString();
            }

            largeScreenRightVO.setValue(count);
            // 设置name
            switch (largeScreenRightVO.getType()) {
                case 1:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.宿舍_教_实验劳动.getName());
                    break;
                case 2:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.校内公共区劳动.getName());
                    break;
                case 3:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.学校服务资源劳动.getName());
                    break;
                case 4:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.劳动报告心得体会.getName());
                    break;
                case 5:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.大学生创新创业.getName());
                    break;
                case 6:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.互联网_报告.getName());
                    break;
                case 7:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.演讲比赛_知识竞赛.getName());
                    break;
                case 8:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.劳动执行_文明宿舍.getName());
                    break;
                case 9:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.公益活动.getName());
                    break;
                case 10:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.科技帮扶报告.getName());
                    break;
                case 11:
                    largeScreenRightVO.setName(BasicLabourCategoryEnum.劳动周报告.getName());
            }
        }
        return list;
    }

    @Override
    public LargeScreenBottomVo getBottomData() {
            // 获取劳动实践完成人数
            List<LabourPracticeVO> list = burialPointMapper.getLabourPracticePeoplesByXyAndNj();
            List<ProUser> proUsers = proUserMapper.selectProUserList(null);
            int peoples = proUsers.size();

            // 前端返回的对象
            LargeScreenBottomVo largeScreenBottomVo = new LargeScreenBottomVo();
            List<LargeScreenBottomClidrenVo> bottomClidrenVos = dataConstruction();

            ArrayList<String> jcData = new ArrayList<>();
            ArrayList<String> gyData = new ArrayList<>();
            ArrayList<String> cgData = new ArrayList<>();
            ArrayList<String> zjData = new ArrayList<>();
            ArrayList<String> xyNames = new ArrayList<>();

        // 过滤掉所有百分比都为0的学院
        List<LabourPracticeVO> filteredList = list.stream()
                .filter(vo -> vo.getJcCount() > 0 || vo.getGyCount() > 0 || vo.getCgCount() > 0 || vo.getZjCount() > 0)
                .collect(Collectors.toList());

            // 学院名称获取
        filteredList.forEach(vo -> {
                xyNames.add(vo.getXyName());
            });

            // 计算每个学院的总和并排序
            List<LabourPracticeVO> sortedList = filteredList.stream()
                    .sorted((vo1, vo2) -> {
                        double total1 = (vo1.getJcCount() + vo1.getGyCount() + vo1.getCgCount() + vo1.getZjCount()) * 100.0 / vo1.getAllCount();
                        double total2 = (vo2.getJcCount() + vo2.getGyCount() + vo2.getCgCount() + vo2.getZjCount()) * 100.0 / vo2.getAllCount();
                        return Double.compare(total2, total1); // 降序排序
                    })
                    .collect(Collectors.toList());

            // 清空原数据，重新填充排序后的数据
            jcData.clear();
            gyData.clear();
            cgData.clear();
            zjData.clear();
            xyNames.clear();

            // 填充排序后的数据
            for (LabourPracticeVO vo : sortedList) {
                xyNames.add(vo.getXyName());

                BigDecimal countJc = vo.getAllCount() > 0 && vo.getJcCount() > 0
                        ? new BigDecimal(vo.getJcCount())
                        .divide(new BigDecimal(vo.getAllCount()), 2, RoundingMode.HALF_UP)
                        .multiply(new BigDecimal(100))
                        : new BigDecimal(0);
                jcData.add(countJc.toString());

                BigDecimal countGy = vo.getAllCount() > 0 && vo.getGyCount() > 0
                        ? new BigDecimal(vo.getGyCount())
                        .divide(new BigDecimal(vo.getAllCount()), 2, RoundingMode.HALF_UP)
                        .multiply(new BigDecimal(100))
                        : new BigDecimal(0);
                gyData.add(countGy.toString());

                BigDecimal countCg = vo.getAllCount() > 0 && vo.getCgCount() > 0
                        ? new BigDecimal(vo.getCgCount())
                        .divide(new BigDecimal(vo.getAllCount()), 2, RoundingMode.HALF_UP)
                        .multiply(new BigDecimal(100))
                        : new BigDecimal(0);
                cgData.add(countCg.toString());

                BigDecimal countZj = vo.getAllCount() > 0 && vo.getZjCount() > 0
                        ? new BigDecimal(vo.getZjCount())
                        .divide(new BigDecimal(vo.getAllCount()), 2, RoundingMode.HALF_UP)
                        .multiply(new BigDecimal(100))
                        : new BigDecimal(0);
                zjData.add(countZj.toString());
            }

            // 设置数据到 LargeScreenBottomClidrenVo
            for (LargeScreenBottomClidrenVo childVo : bottomClidrenVos) {
                switch (childVo.getName()) {
                    case "基础劳动百分比":
                        childVo.setData(jcData.toArray(new String[0]));
                        break;
                    case "社会公益劳动百分比":
                        childVo.setData(gyData.toArray(new String[0]));
                        break;
                    case "劳动成果百分比":
                        childVo.setData(cgData.toArray(new String[0]));
                        break;
                    case "劳动总结报告百分比":
                        childVo.setData(zjData.toArray(new String[0]));
                        break;
                }
            }

            // 设置最终结果
            largeScreenBottomVo.setXys(xyNames.toArray(new String[0]));
            largeScreenBottomVo.setSeries(bottomClidrenVos);

            return largeScreenBottomVo;
        }
//        // 获取劳动实践完成人数
//        List<LabourPracticeVO> list = burialPointMapper.getLabourPracticePeoplesByXyAndNj();
//        List<ProUser> proUsers = proUserMapper.selectProUserList(null);
//        int peoples = proUsers.size();
//
//        // 前端返回的对象
//        LargeScreenBottomVo largeScreenBottomVo = new LargeScreenBottomVo();
//        List<LargeScreenBottomClidrenVo> bottomClidrenVos = dataConstruction();
//
//        ArrayList<String> jcData = new ArrayList<>();
//        ArrayList<String> gyData = new ArrayList<>();
//        ArrayList<String> cgData = new ArrayList<>();
//        ArrayList<String> zjData = new ArrayList<>();
//        ArrayList<String> xyNames = new ArrayList<>();
//
//        // 学院名称获取
//        list.forEach(vo -> {
//            xyNames.add(vo.getXyName());
//        });
//
//        for (LargeScreenBottomClidrenVo largeScreenBottomClidrenVo : bottomClidrenVos) {
//            for (LabourPracticeVO labourPracticeVO : list) {
//                switch (largeScreenBottomClidrenVo.getName()) {
//                    case "基础劳动百分比" :
//                         BigDecimal countJc =  labourPracticeVO.getAllCount() > 0 && labourPracticeVO.getJcCount() > 0
//                                 ? new BigDecimal(labourPracticeVO.getJcCount())
//                                 .divide(new BigDecimal( labourPracticeVO.getAllCount()),2,RoundingMode.HALF_UP)
//                                 .multiply(new BigDecimal(100))
//                                 : new BigDecimal(0);
//                        jcData.add(countJc.toString());
//                        break;
//                    case "社会公益劳动百分比" :
//                        BigDecimal countGy =  labourPracticeVO.getAllCount() > 0 && labourPracticeVO.getGyCount() > 0
//                                ? new BigDecimal(labourPracticeVO.getGyCount())
//                                .divide(new BigDecimal( labourPracticeVO.getAllCount()),2,RoundingMode.HALF_UP)
//                                .multiply(new BigDecimal(100))
//                                : new BigDecimal(0);
//                        gyData.add(countGy.toString());
//                        break;
//                    case "劳动成果百分比" :
//                        BigDecimal countCg =  labourPracticeVO.getAllCount() > 0 && labourPracticeVO.getCgCount() > 0
//                                ? new BigDecimal(labourPracticeVO.getCgCount())
//                                .divide(new BigDecimal( labourPracticeVO.getAllCount()),2,RoundingMode.HALF_UP)
//                                .multiply(new BigDecimal(100))
//                                : new BigDecimal(0);
//                        cgData.add(countCg.toString());
//                        break;
//                    case "劳动总结报告百分比" :
//                        BigDecimal countZj =  labourPracticeVO.getAllCount() > 0 && labourPracticeVO.getZjCount() > 0
//                                ? new BigDecimal(labourPracticeVO.getZjCount())
//                                .divide(new BigDecimal( labourPracticeVO.getAllCount()),2,RoundingMode.HALF_UP)
//                                .multiply(new BigDecimal(100))
//                                : new BigDecimal(0);
//                        zjData.add(countZj.toString());
//                        break;
//                }
//            }
//            switch (largeScreenBottomClidrenVo.getName()) {
//                case "基础劳动百分比" :
//                    largeScreenBottomClidrenVo.setData(jcData.toArray(new String[0]));
//                    break;
//                case "社会公益劳动百分比" :
//                    largeScreenBottomClidrenVo.setData(gyData.toArray(new String[0]));
//                    break;
//                case "劳动成果百分比" :
//                    largeScreenBottomClidrenVo.setData(cgData.toArray(new String[0]));
//                    break;
//                case "劳动总结报告百分比" :
//                    largeScreenBottomClidrenVo.setData(zjData.toArray(new String[0]));
//                    break;
//            }
//        }
//
//        largeScreenBottomVo.setXys(xyNames.toArray(new String[0]));
//        largeScreenBottomVo.setSeries(bottomClidrenVos);
//        return largeScreenBottomVo;
//    }

    @Override
    public List<LabourScreenLeftMoreVO> getLeftMoreData() {
        ArrayList<LabourScreenLeftMoreVO> labourScreenLeftMoreVOS = new ArrayList<>();

        // 获取劳动教育总得分（以学院、年级为纬度）
        List<LabourEducationAverageVO> list = burialPointMapper.getLabourEducationAverageByXyAndNj();
        System.out.println(list);
        // 按照学院、年级分组
        Map<String, Map<String, List<LabourEducationAverageVO>>> collect = list.stream().
                collect(Collectors.groupingBy(LabourEducationAverageVO::getXyName,
                        Collectors.groupingBy(LabourEducationAverageVO::getNjName)));

        // 遍历外层Map
        for (Map.Entry<String, Map<String, List<LabourEducationAverageVO>>> outerEntry : collect.entrySet()) {
            LabourScreenLeftMoreVO labourScreenLeftMoreVO = new LabourScreenLeftMoreVO();

            String outerKey = outerEntry.getKey();
            labourScreenLeftMoreVO.setXyName(outerKey);
            Map<String, List<LabourEducationAverageVO>> innerMap = outerEntry.getValue();
            // 遍历内层Map
            for (Map.Entry<String, List<LabourEducationAverageVO>> innerEntry : innerMap.entrySet()) {
                String innerKey = innerEntry.getKey();
                labourScreenLeftMoreVO.setNjName(innerKey);
                List<LabourEducationAverageVO> valueList = innerEntry.getValue();

                BigDecimal xyNjCount = BigDecimal.ZERO;
                // 遍历List
                for (LabourEducationAverageVO item : valueList) {
                    BigDecimal jcldCj = item.getUserjcldCj().setScale(2, RoundingMode.HALF_UP);
                    BigDecimal cgCj = item.getUserldcgCj().setScale(2, RoundingMode.HALF_UP);
                    BigDecimal gyCj = item.getUserldgyCj().setScale(2, RoundingMode.HALF_UP);
                    BigDecimal zjCj = item.getUserldzjCj().setScale(2, RoundingMode.HALF_UP);
                    BigDecimal llCj = item.getUserllCj().setScale(2, RoundingMode.HALF_UP);

                    BigDecimal jcldCjZS = jcldCj.multiply(BigDecimal.valueOf(0.6)).setScale(2, RoundingMode.HALF_UP);
                    BigDecimal ldzjCjZS = zjCj.multiply((BigDecimal.valueOf(0.2))).setScale(2, RoundingMode.HALF_UP);
                    BigDecimal ldgyCjZS = gyCj.multiply((BigDecimal.valueOf(0.1))).setScale(2, RoundingMode.HALF_UP);
                    BigDecimal ldcgCjZS = cgCj.multiply((BigDecimal.valueOf(0.1))).setScale(2, RoundingMode.HALF_UP);
                    BigDecimal countSjZs = jcldCjZS.add(ldzjCjZS).add(ldgyCjZS).add(ldcgCjZS);
                    BigDecimal allCount = llCj.multiply(BigDecimal.valueOf(0.2)).add(countSjZs.multiply(BigDecimal.valueOf(0.8)));
                    xyNjCount = xyNjCount.add(allCount);
                }
                labourScreenLeftMoreVO.setAllCount(xyNjCount.compareTo(BigDecimal.ZERO) > 0 && valueList.size() > 0
                        ?  xyNjCount.divide(new BigDecimal(valueList.size()),2,RoundingMode.HALF_UP).doubleValue()
                        : 0);
            }
            labourScreenLeftMoreVOS.add(labourScreenLeftMoreVO);
        }
        labourScreenLeftMoreVOS.sort(Comparator.comparingDouble(LabourScreenLeftMoreVO::getAllCount).reversed());
        return labourScreenLeftMoreVOS.stream().filter(vo -> vo.getAllCount() != 0).collect(Collectors.toList());
    }

    @Override
    public List<LabourLeftDataCopyVo> getLeftDataCopy() {
        // 获取劳动教育总得分（以学院、年级为纬度）
        List<LabourEducationAverageVO> list = burialPointMapper.getLabourEducationAverageByXyAndNjCopy();
        // 按学院进行分组
        Map<String, List<LabourEducationAverageVO>> xyIdGroup = list.stream().
                collect(Collectors.groupingBy(LabourEducationAverageVO::getXyId));
        ArrayList<String> xyIdGroupArrays = new ArrayList<>(xyIdGroup.keySet());
        List<LabourLeftDataCopyVo> labourLeftDataCopyVos = new ArrayList<>();
        for (String xyIdGroupArray : xyIdGroupArrays) {
            LabourLeftDataCopyVo labourLeftDataCopyVo = new LabourLeftDataCopyVo();
            ArrayList<LabourLeftDataCopyClidrenVo> labourLeftDataCopyClidrenVos = new ArrayList<>();
            int xy = 0;
            BigDecimal bigDecimal = BigDecimal.ZERO;
            for (LabourEducationAverageVO vo : list) {
                if (vo.getXyId().equals(xyIdGroupArray)) {
                    if (xy == 0) {
                        labourLeftDataCopyVo.setXyName(vo.getXyName());
                    }

                    LabourLeftDataCopyClidrenVo labourLeftDataCopyClidrenVo = new LabourLeftDataCopyClidrenVo();
                    BigDecimal jcldCj = vo.getUserjcldCj().setScale(2, RoundingMode.HALF_UP);
                    BigDecimal cgCj = vo.getUserldcgCj().setScale(2, RoundingMode.HALF_UP);
                    BigDecimal gyCj = vo.getUserldgyCj().setScale(2, RoundingMode.HALF_UP);
                    BigDecimal zjCj = vo.getUserldzjCj().setScale(2, RoundingMode.HALF_UP);
                    BigDecimal llCj = vo.getUserllCj().setScale(2, RoundingMode.HALF_UP);

                    BigDecimal jcldCjZS = jcldCj.multiply(BigDecimal.valueOf(0.6)).setScale(2, RoundingMode.HALF_UP);
                    BigDecimal ldzjCjZS = zjCj.multiply((BigDecimal.valueOf(0.2))).setScale(2, RoundingMode.HALF_UP);
                    BigDecimal ldgyCjZS = gyCj.multiply((BigDecimal.valueOf(0.1))).setScale(2, RoundingMode.HALF_UP);
                    BigDecimal ldcgCjZS = cgCj.multiply((BigDecimal.valueOf(0.1))).setScale(2, RoundingMode.HALF_UP);
                    BigDecimal countSjZs = jcldCjZS.add(ldzjCjZS).add(ldgyCjZS).add(ldcgCjZS);
                    BigDecimal allCount = llCj.multiply(BigDecimal.valueOf(0.2)).add(countSjZs.multiply(BigDecimal.valueOf(0.8)));
                    String value = allCount.compareTo(BigDecimal.ZERO) > 0 && vo.getPeoples() > 0
                            ? allCount.divide(new BigDecimal(vo.getPeoples()), 2, RoundingMode.HALF_UP).toString()
                            : "";

                    labourLeftDataCopyClidrenVo.setNjName(vo.getNjName());
                    labourLeftDataCopyClidrenVo.setValue(value);
                    labourLeftDataCopyClidrenVos.add(labourLeftDataCopyClidrenVo);
                    BigDecimal valueLong = StringUtils.isEmpty(value) ? new BigDecimal(0) : new BigDecimal(value);
                    bigDecimal = bigDecimal.add(valueLong);
                    xy++;
                }
            }
            labourLeftDataCopyVo.setLabourLeftDataCopyVos(labourLeftDataCopyClidrenVos);
            labourLeftDataCopyVo.setValues(bigDecimal);
            labourLeftDataCopyVos.add(labourLeftDataCopyVo);
        }
        List<LabourLeftDataCopyVo> collect = labourLeftDataCopyVos.stream().filter(vos -> vos.getValues().compareTo(new BigDecimal(0)) > 0)
                .collect(Collectors.toList());
        return collect.stream().sorted(Comparator.comparing(LabourLeftDataCopyVo::getValues).reversed())
                .collect(Collectors.toList());
    }

    @Override
    public List<LabourLeftDataCopyVo> getLeftMoreDataCopy() {
        // 获取劳动教育总得分（以学院、年级为纬度）
        List<LabourEducationAverageVO> list = burialPointMapper.getLabourEducationAverageByXyAndNjCopy();
        ArrayList<LabourLeftDataCopyVo> labourLeftDataCopyVos = new ArrayList<>();
        for (LabourEducationAverageVO vo : list) {
            LabourLeftDataCopyVo labourLeftDataCopyVo = new LabourLeftDataCopyVo();
            BigDecimal jcldCj = vo.getUserjcldCj().setScale(2, RoundingMode.HALF_UP);
            BigDecimal cgCj = vo.getUserldcgCj().setScale(2, RoundingMode.HALF_UP);
            BigDecimal gyCj = vo.getUserldgyCj().setScale(2, RoundingMode.HALF_UP);
            BigDecimal zjCj = vo.getUserldzjCj().setScale(2, RoundingMode.HALF_UP);
            BigDecimal llCj = vo.getUserllCj().setScale(2, RoundingMode.HALF_UP);

            BigDecimal jcldCjZS = jcldCj.multiply(BigDecimal.valueOf(0.6)).setScale(2, RoundingMode.HALF_UP);
            BigDecimal ldzjCjZS = zjCj.multiply((BigDecimal.valueOf(0.2))).setScale(2, RoundingMode.HALF_UP);
            BigDecimal ldgyCjZS = gyCj.multiply((BigDecimal.valueOf(0.1))).setScale(2, RoundingMode.HALF_UP);
            BigDecimal ldcgCjZS = cgCj.multiply((BigDecimal.valueOf(0.1))).setScale(2, RoundingMode.HALF_UP);
            BigDecimal countSjZs = jcldCjZS.add(ldzjCjZS).add(ldgyCjZS).add(ldcgCjZS);
            BigDecimal allCount = llCj.multiply(BigDecimal.valueOf(0.2)).add(countSjZs.multiply(BigDecimal.valueOf(0.8)));
            String value = allCount.compareTo(BigDecimal.ZERO) > 0 && vo.getPeoples() > 0
                    ? allCount.divide(new BigDecimal(vo.getPeoples()), 2, RoundingMode.HALF_UP).toString()
                    : "";
            labourLeftDataCopyVo.setXyName(vo.getXyName());
            labourLeftDataCopyVo.setNjName(vo.getNjName());
            labourLeftDataCopyVo.setValue(value);
            labourLeftDataCopyVos.add(labourLeftDataCopyVo);
        }
        return labourLeftDataCopyVos.stream().sorted(Comparator.comparing(LabourLeftDataCopyVo::getValue).reversed())
                .collect(Collectors.toList());
    }

    @Override
    public LargeScreenBottomVo getBottomDataCopy() {
        return null;
    }

    /**
     * 数据建造
     * @return
     */
    private List<LargeScreenBottomClidrenVo> dataConstruction() {
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("focus","series");
        ArrayList<LargeScreenBottomClidrenVo> largeScreenBottomClidrenVos = new ArrayList<>();
        LargeScreenBottomClidrenVo oneClidrenVo = LargeScreenBottomClidrenVo.builder()
                .name("基础劳动百分比")
                .type("bar")
                .stack("Ad")
                .emphasis(stringStringHashMap)
                .build();
        LargeScreenBottomClidrenVo twoClidrenVo = LargeScreenBottomClidrenVo.builder()
                .name("社会公益劳动百分比")
                .type("bar")
                .stack("Ad")
                .emphasis(stringStringHashMap)
                .build();
        LargeScreenBottomClidrenVo threeClidrenVo = LargeScreenBottomClidrenVo.builder()
                .name("劳动成果百分比")
                .type("bar")
                .stack("Ad")
                .emphasis(stringStringHashMap)
                .build();
        LargeScreenBottomClidrenVo fourClidrenVo = LargeScreenBottomClidrenVo.builder()
                .name("劳动总结报告百分比")
                .type("bar")
                .stack("Ad")
                .emphasis(stringStringHashMap)
                .build();
        largeScreenBottomClidrenVos.add(oneClidrenVo);
        largeScreenBottomClidrenVos.add(twoClidrenVo);
        largeScreenBottomClidrenVos.add(threeClidrenVo);
        largeScreenBottomClidrenVos.add(fourClidrenVo);
        return largeScreenBottomClidrenVos;
    }

    /**
     * 获取最近月份
     * @param number 几个月份
     * @return
     */
    private static List<String> getRecentMonths(int number) {
        List<String> months = new ArrayList<>();
        LocalDate now = LocalDate.now();
        for (int i = 0; i < number; i++) {
            months.add(now.minusMonths(i).format(DateTimeFormatter.ofPattern("yyyy-MM")));
        }
        Collections.reverse(months);
        return months;
    }
}
